<template>
    <div class="login_container">
       <div class="login_box">
          <div class="avatr_logo">
            <img src="../assets/lancart.webp" alt="">
          </div>

          <el-form :model="loginForm" ref="loginFormRef" :rules="loginFormRules" label-width="50px">
              <el-form-item label="账号" prop="username">
                <el-input v-model="loginForm.username" prefix-icon="el-icon-user" ></el-input>
              </el-form-item>
              <el-form-item label="密码" prop="password">
                <el-input v-model="loginForm.password" prefix-icon="el-icon-loading"></el-input>
              </el-form-item>
              <el-form-item class="btn">
                <el-button type="primary" @click="login">登录</el-button>
                <el-button type="primary" @click="reset">重置</el-button>
              </el-form-item>
          </el-form>
       </div>
    </div>
</template>

<script>
    export default {
         name:'loginIndex',
         data () {
          return {
             loginForm:{
                username:'admin',
                password:'123456'
             },
             loginFormRules:{
               username:[
                 { required: true, message: '请输入账号', trigger: 'blur' },
                //  { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
                ],
                password:[
                  { required: true, message: '请输入活动名称', trigger: 'blur' },
                  // { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
                ]
             }
          }
         },
         methods:{
          reset(){
            this.$refs.loginFormRef.resetFields()
          },
          login(){
            this.$refs.loginFormRef.validate(async (isOk)=>{
                  if(!isOk) return
                 const {data:res} = await this.$http.post('/login',this.loginForm)
                 if(res.meta.status !== 200) return this.$message.error('登录失败')
                 this.$message.success('登录成功')
                 sessionStorage.setItem('token',res.data.token)
                 this.$router.push('/home')
            })
          }
         }
    }
</script>

<style lang="less" scoped>
  .login_container{
    background-color: rgb(187, 127, 255);
    height: 100%;
  }
  .login_box{
     width: 450px;
     height: 300px;
     background-color: aliceblue;
     border-radius: 3px;
     position: relative;
     top: 50%;
     left: 50%;
     transform: translate(-50%,-50%);


     .avatr_logo{
      width: 130px;
      height: 130px;
      border-radius: 50%;
      position: relative;
      left: 50%;
      transform: translate(-50%,-50%);
       img{
        width: 100%;
        height: 100%;
        border-radius: 50%;
        
       }
     }
     .forcss{
      box-sizing: border-box;
      .btn{
      padding-right: 20px;
       display: flex;
       justify-content: flex-end;
     }
     }
     
  }
</style>